# coding:utf-8
# @Time    : 2021/12/10 8:54
# @Author  : Martin

"""
家乐福单行直降
"""
from page_object.base.page_items_carrefour import PageItemsCarrefour
from util.read_file import get_approve_data


class SingleLinePage(PageItemsCarrefour):
    _base_url = "/nspas-web-in/processRoleFilter.do?businessTemplateId=NSOA23978"

    def input_act_rule(self, rule_type, rule_detail):
        """
        活动规则
        :param rule_detail: 门槛信息
        :param rule_type:
                   331 满件减元（同商品）
                   333 满件打折（同商品）
                   431 第X件优惠Y元（同商品）
                   433 第X件打Y折（同商品）
        :return:
        """
        # rule_type = params['rule_type']
        # 勾选优惠类型
        self.single_checked('xpath', f'//input[@name="ruleOption"][@value="{rule_type}"]')
        # rule_detail = params['rule_detail']
        for level in rule_detail:
            print(level)
            index = rule_detail.index(level) + 1
            # 门槛，优惠金额
            # limit, discount = level
            # 输入门槛
            self.input('css selector', f'#detailinfoOrderOfflinePlummetRule>table:nth-child({index})'
                                       ' input[name="orderPlummetRule.privilegeSill"]', level['limit'])
            # 输入优惠
            self.input('css selector', f'#detailinfoOrderOfflinePlummetRule>table:nth-child({index})'
                                       ' input[name="orderPlummetRule.plummet"]', level['discount'])
            if index != len(rule_detail):
                self.click('xpath', '//a[@onclick="orderPlummetAdd();"]')

    @staticmethod
    def get_approve_head_create():
        """
        获取总部新建审批流账号数据
        :return:
        """
        return get_approve_data('jlf_single_line', 'head', 'create')
